//
// Created by fl on 23-9-5.
//

#ifndef SIGMA_GUIDANCE_GET_TIME_H
#define SIGMA_GUIDANCE_GET_TIME_H

#include <iostream>
#include <sys/time.h>

// 单位毫秒
static uint64_t currentTimeMs()
{
    struct timeval tv{};
    gettimeofday(&tv,nullptr);    //该函数在sys/time.h头文件中
    return tv.tv_sec * 1000 + tv.tv_usec / 1000;
}


// 单位毫秒
static uint64_t elapsedTimeMs(uint64_t t)
{
    return currentTimeMs() - t;
}

// 单位微秒
static uint64_t currentTimeUs()
{
    struct timeval tv{};
    gettimeofday(&tv,nullptr);    //该函数在sys/time.h头文件中
    return tv.tv_sec * 1e6 + tv.tv_usec;
}

// 单位微秒
static uint64_t elapsedTimeUs(uint64_t t)
{
    return currentTimeUs() - t;
}

#endif //SIGMA_GUIDANCE_GET_TIME_H
